﻿#include "meetingway.h"
#include "ui_meetingway.h"
#include"datachange/sqlconnect.h"
#include <QPalette>
#include<QCoreApplication>
#include<QFileDialog>
#include<QFileInfo>
#include<QPrinter>
#include<QTextDocument>
#include<QTextBlock>
#include<QMessageBox>
#include<QColor>
meetingWay::meetingWay(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::meetingWay)
{
    ui->setupUi(this);
    //初始化会议方案页面控件
    /*调整控件*/
    widgetAdjust();
    //按钮信号槽
    connect(ui->editButton,SIGNAL(clicked(bool)),this,SLOT(click_lock()));//添加会议
    connect(ui->del_meet_but,SIGNAL(clicked(bool)),this,SLOT(del_meet()));
    connect(ui->add_but_per,SIGNAL(clicked(bool)),this,SLOT(add_record()));
    connect(ui->del_but_per,SIGNAL(clicked(bool)),this,SLOT(del_record()));
    //connect(ui->editPost,SIGNAL(clicked(bool)),this,SLOT(editPost()));
    //初始化菜单,对会议方案的操作
    init_menu();
    //初始化显示数据库数据
    connect(ui->meetingTable,SIGNAL(cellClicked(int,int)),this,SLOT(showMeetPer()));
    showdatabase();//显示会议方案数据
    //显示会议人员整体信息
    //先清除
    //connect(ui->peoplemeet,SIGNAL(cellClicked(int,int)),this,SLOT(clearTable()));
    connect(ui->peoplemeet,SIGNAL(cellClicked(int,int)),this,SLOT(showMeetPerInfo()));
    //db.close();
    //showdatabase();
}

meetingWay::~meetingWay()
{
    delete ui;
}



//调整控件操作
void meetingWay::widgetAdjust(){
    ui->meetingTable->horizontalHeader()->setResizeMode(0, QHeaderView::ResizeToContents);
    ui->meetingTable->horizontalHeader()->setResizeMode(1, QHeaderView::ResizeToContents);
    ui->meetingTable->horizontalHeader()->setResizeMode(2, QHeaderView::ResizeToContents);
    ui->meetingTable->horizontalHeader()->setResizeMode(3, QHeaderView::ResizeToContents);
    ui->meetingTable->horizontalHeader()->setResizeMode(4, QHeaderView::ResizeToContents);
    ui->peoplemeet->horizontalHeader()->setResizeMode(0, QHeaderView::ResizeToContents);
    ui->peoplemeet->horizontalHeader()->setResizeMode(1, QHeaderView::ResizeToContents);
    ui->peoplemeet->horizontalHeader()->setResizeMode(2, QHeaderView::ResizeToContents);
    ui->peoplemeet->horizontalHeader()->setResizeMode(3, QHeaderView::ResizeToContents);
    ui->peoplemeet->horizontalHeader()->setResizeMode(4, QHeaderView::ResizeToContents);
    ui->peoplemeet->horizontalHeader()->setResizeMode(5, QHeaderView::ResizeToContents);
    ui->peoplemeet->horizontalHeader()->setResizeMode(6, QHeaderView::ResizeToContents);
    ui->peoplemeet->horizontalHeader()->setResizeMode(7, QHeaderView::ResizeToContents);
    ui->eduTable->horizontalHeader()->setResizeMode(0, QHeaderView::ResizeToContents);
    ui->eduTable->horizontalHeader()->setResizeMode(1, QHeaderView::ResizeToContents);
    ui->eduTable->horizontalHeader()->setResizeMode(2, QHeaderView::ResizeToContents);
    ui->eduTable->horizontalHeader()->setResizeMode(3, QHeaderView::ResizeToContents);
    ui->eduTable->horizontalHeader()->setResizeMode(4, QHeaderView::ResizeToContents);
    ui->eduTable->horizontalHeader()->setResizeMode(5, QHeaderView::ResizeToContents);
    ui->eduTable->horizontalHeader()->setResizeMode(6, QHeaderView::ResizeToContents);
    ui->eduTable->horizontalHeader()->setResizeMode(7, QHeaderView::ResizeToContents);
    ui->workExperience->horizontalHeader()->setResizeMode(0, QHeaderView::ResizeToContents);
    ui->workExperience->horizontalHeader()->setResizeMode(1, QHeaderView::ResizeToContents);
    ui->workExperience->horizontalHeader()->setResizeMode(2, QHeaderView::ResizeToContents);
    ui->workExperience->horizontalHeader()->setResizeMode(3, QHeaderView::ResizeToContents);
    ui->checkTable->horizontalHeader()->setResizeMode(0, QHeaderView::ResizeToContents);
    ui->checkTable->horizontalHeader()->setResizeMode(1, QHeaderView::ResizeToContents);
    ui->rewardTable->horizontalHeader()->setResizeMode(0, QHeaderView::ResizeToContents);
    ui->rewardTable->horizontalHeader()->setResizeMode(1, QHeaderView::ResizeToContents);
    ui->rewardTable->horizontalHeader()->setResizeMode(2, QHeaderView::ResizeToContents);
    ui->rewardTable->horizontalHeader()->setResizeMode(3, QHeaderView::ResizeToContents);
    ui->rewardTable->horizontalHeader()->setResizeMode(4, QHeaderView::ResizeToContents);
    ui->punishTable->horizontalHeader()->setResizeMode(0, QHeaderView::ResizeToContents);
    ui->punishTable->horizontalHeader()->setResizeMode(1, QHeaderView::ResizeToContents);
    ui->punishTable->horizontalHeader()->setResizeMode(2, QHeaderView::ResizeToContents);
    ui->punishTable->horizontalHeader()->setResizeMode(3, QHeaderView::ResizeToContents);
    ui->punishTable->horizontalHeader()->setResizeMode(4, QHeaderView::ResizeToContents);
    ui->familyTable->horizontalHeader()->setResizeMode(0, QHeaderView::ResizeToContents);
    ui->familyTable->horizontalHeader()->setResizeMode(1, QHeaderView::ResizeToContents);
    ui->familyTable->horizontalHeader()->setResizeMode(2, QHeaderView::ResizeToContents);
    ui->familyTable->horizontalHeader()->setResizeMode(3, QHeaderView::ResizeToContents);
    ui->familyTable->horizontalHeader()->setResizeMode(4, QHeaderView::ResizeToContents);
    ui->familyTable->horizontalHeader()->setResizeMode(5, QHeaderView::ResizeToContents);
    ui->familyTable->horizontalHeader()->setResizeMode(6, QHeaderView::ResizeToContents);
    //设置table控件状态
    ui->meetingTable->setSelectionBehavior ( QAbstractItemView::SelectRows); //设置选择行为，以行为单位
    ui->meetingTable->setSelectionMode ( QAbstractItemView::SingleSelection); //设置选择模式，选择单行
    ui->meetingTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
    ui->meetingTable->setFocusPolicy(Qt::NoFocus);
    //ui->peoplemeet->setSelectionBehavior ( QAbstractItemView::SelectRows);
    //ui->peoplemeet->setSelectionMode ( QAbstractItemView::SingleSelection); //设置选择模式，选择单行
    //ui->peoplemeet->setEditTriggers(QAbstractItemView::NoEditTriggers);
    //ui->peoplemeet->setFocusPolicy(Qt::NoFocus);
    ui->peoplemeet->setSelectionBehavior(QAbstractItemView::SelectRows);  //整行选中的方式
    ui->peoplemeet->setSelectionMode(QAbstractItemView::SingleSelection);  //设置为可以选中单个
    ui->eduTable->setSelectionBehavior ( QAbstractItemView::SelectRows);
    ui->eduTable->setSelectionMode ( QAbstractItemView::SingleSelection);
    ui->eduTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
    ui->workExperience->setSelectionBehavior ( QAbstractItemView::SelectRows);
    ui->workExperience->setSelectionMode ( QAbstractItemView::SingleSelection);
    ui->workExperience->setEditTriggers(QAbstractItemView::NoEditTriggers);
    ui->checkTable->setSelectionBehavior ( QAbstractItemView::SelectRows);
    ui->checkTable->setSelectionMode ( QAbstractItemView::SingleSelection);
    ui->checkTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
    ui->rewardTable->setSelectionBehavior ( QAbstractItemView::SelectRows);
    ui->rewardTable->setSelectionMode ( QAbstractItemView::SingleSelection);
    ui->rewardTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
    ui->punishTable->setSelectionBehavior ( QAbstractItemView::SelectRows);
    ui->punishTable->setSelectionMode ( QAbstractItemView::SingleSelection);
    ui->punishTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
    ui->familyTable->setSelectionBehavior ( QAbstractItemView::SelectRows);
    ui->familyTable->setSelectionMode ( QAbstractItemView::SingleSelection);
    ui->familyTable->setEditTriggers(QAbstractItemView::NoEditTriggers);


    ui->name->setEnabled(false);
    ui->usedname->setEnabled(false);
    ui->IDType->setEnabled(false);
    ui->IDNum->setEnabled(false);

    ui->borndate->setEnabled(false);
    ui->workdate->setEnabled(false);
    ui->sex->setEnabled(false);
    ui->health->setEnabled(false);

    ui->nation->setEnabled(false);
    ui->nativePlace->setEnabled(false);
    ui->bornPlace->setEnabled(false);
    ui->growPlace->setEnabled(false);

    ui->politic->setEnabled(false);
    ui->partyDate->setEnabled(false);
    ui->demoParty->setEnabled(false);
    ui->retirechange->setEnabled(false);

    ui->speciality->setEnabled(false);
    ui->manageID->setEnabled(false);
    ui->idencate->setEnabled(false);
    ui->threeone->setEnabled(false);
    ui->baseexper->setEnabled(false);
    ui->unitid->setEnabled(false);
    ui->phone->setEnabled(false);

    ui->rankid->setEnabled(false);
    ui->daiyuEdit->setEnabled(false);
    ui->ranktime->setEnabled(false);

}



//输出菜单初始化
void meetingWay::init_menu(){
    //Button = new QPushButton(this);
    //Button->setFixedSize(78,30);
    menu=new QMenu();
    //QAction *waytable = new QAction(menu);     //方案表
    QAction *jduge = new QAction(menu);  //表决票
    QAction *statistic = new QAction(menu);//统计表
    QAction *cadrelist = new QAction(menu);//干部名单表
    //waytable->setText("方案表");
    jduge->setText("表决票");
    statistic->setText("统计表");
    cadrelist->setText("干部名单表");
    menu->addAction(jduge);
    menu->addSeparator();
    menu->addAction(statistic);
    menu->addSeparator();
    menu->addAction(cadrelist);
    ui->menuButton->setMenu(menu);
    connect(jduge,SIGNAL(triggered()),this,SLOT(out_jduge()));
    connect(statistic,SIGNAL(triggered()),this,SLOT(out_statistic()));
    connect(cadrelist,SIGNAL(triggered()),this,SLOT(out_cadre()));
}
//表决票html
QString meetingWay::jduge_html(QString Q){
        int count=ui->peoplemeet->rowCount();//会议讨论人员数
        QString html = "";
        html += "<html>";
        html += "<head>";
        html += "<title>"+Q+"</title>";
        html += "<head>";
        html += "<body>";
        html += "<h1>表决票</h1>";
        //html += "</table>";
        html += "<table width=\"100%\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">";
        html += "<tr>";
        html += "<td>序号</td>";
        html += "<td>姓名</td>";
        html += "<td>现任职务</td>";
        html += "<td>拟任职务</td>";
        html += "<td>拟免职务</td>";
 /*       html += "<td><table width=\"100%\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">";
        html += "<tr>";
        html += "<td colspan=\"4\">表决意见</td>";//colspan="3"
        html += "</tr>";
        html += "<tr>";
        html += "<td>赞成</td>";
        html += "<td>反对</td>";
        html += "<td>暂缓</td>";
        html += "<td>弃权</td>";
        html += "</tr>";
        html += "</table></td>";*/
        html += "<td>赞成</td>";
        html += "<td>反对</td>";
        html += "<td>暂缓</td>";
        html += "<td>弃权</td>";
        html += "</tr>";
        int i=0;//讨论人员序号
        //int j=0;//讨论人员序号
        //qDebug()<<"咋回事";
        while(count>0){

        html += "<tr>";
        //序号
        html += "<td>"+QString::number(i)+"</td>";

        qDebug()<<ui->peoplemeet->item(i,0);
        //姓名
        if(ui->peoplemeet->item(i,0)!=NULL)
            html += "<td>"+ui->peoplemeet->item(i,0)->text()+"</td>";
        else
            html += "<td></td>";
        //现任
        if(ui->peoplemeet->item(i,5)!=NULL)
            html += "<td>"+ui->peoplemeet->item(i,5)->text()+"</td>";
        else
            html += "<td></td>";
        //拟任
        if(ui->peoplemeet->item(i,6)!=NULL)
            html += "<td>"+ui->peoplemeet->item(i,6)->text()+"</td>";
        else
            html += "<td></td>";
        //拟免
        if(ui->peoplemeet->item(i,7)!=NULL)
            html += "<td>"+ui->peoplemeet->item(i,7)->text()+"</td>";
        else
            html += "<td></td>";

        html += "<td></td>";
        html += "<td></td>";
        html += "<td></td>";
        html += "<td></td>";
        //html += "<th>"+ui->tableWidget->item(ui->tableWidget->currentRow(),2)->text()+"</th>";
        html += "</tr>";
        count--;
        i++;
        //j++;
        }
        html += "</table>";
        html += "</body>";
        html += "<ml>";
    return html;
}
//统计表
QString meetingWay::statistic_html(QString Q){
    int count=ui->peoplemeet->rowCount();//会议讨论人员数
    QString html = "";
    html += "<html>";
    html += "<head>";
    html += "<title>"+Q+"</title>";
    html += "<head>";
    html += "<body>";
    html += "<h1>统计表</h1>";
    html += "</table>";
    html += "<table width=\"100%\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">";
    html += "<tr>";
    html += "<th>序号</th>";
    html += "<th>姓名</th>";
    html += "<th>现任职务</th>";
    html += "<th>拟任职务</th>";
    html += "<th>拟免职务</th>";
    html += "<th>总赞成</th>";
    html += "<th>总反对</th>";
    html += "<th>总暂缓</th>";
    html += "<th>总弃权</th>";
    html += "</tr>";
    int i=0;//讨论人员序号
    //int j=0;//讨论人员序号
    //qDebug()<<"咋回事";
    while(count>0){
    html += "<tr>";
    //序号
    html += "<th>"+QString::number(i)+"</th>";

    qDebug()<<ui->peoplemeet->item(i,0);
    //姓名
    if(ui->peoplemeet->item(i,0)!=NULL)
        html += "<th>"+ui->peoplemeet->item(i,0)->text()+"</th>";
    else
        html += "<th></th>";
    //现任
    if(ui->peoplemeet->item(i,5)!=NULL)
        html += "<th>"+ui->peoplemeet->item(i,5)->text()+"</th>";
    else
        html += "<th></th>";
    //拟任
    if(ui->peoplemeet->item(i,6)!=NULL)
        html += "<th>"+ui->peoplemeet->item(i,6)->text()+"</th>";
    else
        html += "<th></th>";
    //拟免
    if(ui->peoplemeet->item(i,7)!=NULL)
        html += "<th>"+ui->peoplemeet->item(i,7)->text()+"</th>";
    else
        html += "<th></th>";

    html += "<th></th>";
    html += "<th></th>";
    html += "<th></th>";
    html += "<th></th>";
    //html += "<th>"+ui->tableWidget->item(ui->tableWidget->currentRow(),2)->text()+"</th>";
    html += "</tr>";
    count--;
    i++;
    //j++;
    }
    html += "</table>";
    html +="<br />";
    html+="<b>应到会&nbsp;&nbsp;&nbsp;&nbsp;人，实到会&nbsp;&nbsp;&nbsp;&nbsp;人。</b>";
    html +="<br />";
    html +="<br />";
    html+="<b>计票人：&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;监票人：</b>";
    html += "</body>";
    html += "<ml>";
return html;
}
//干部名单
QString meetingWay::cadre_html(QString Q){
    int count=ui->peoplemeet->rowCount();//会议讨论人员数
    QString html = "";
    html += "<html>";
    html += "<head>";
    html += "<title>"+Q+"</title>";
    html += "<head>";
    html += "<body>";
    html += "<h1>会议讨论任免干部名单</h1>";
    html += "</table>";
    html += "<table width=\"100%\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">";
    html += "<tr>";
    html += "<th width=\"20\">序号</th>";
    html += "<th width=\"30\">姓名</th>";
    html += "<th  width=\"30\">现任职务</th>";
    html += "<th  width=\"80\">现任职务任职时间</th>";
    html += "<th  width=\"30\">拟任职务</th>";
    html += "<th width=\"30\">拟免职务</th>";
    html += "<th width=\"50\">籍贯</th>";
    html += "<th width=\"20\">性别</th>";
    html += "<th width=\"80\">出生年月</th>";
    html += "<th width=\"80\">参加工作时间</th>";
    html += "<th width=\"80\">入党时间</th>";
    html += "<th width=\"30\">最高学历</th>";
    html += "</tr>";
    int i=0;//讨论人员序号
    //int j=0;//讨论人员序号
    //qDebug()<<"咋回事";
    while(count>0){
    html += "<tr>";
    //序号
    html += "<td>"+QString::number(i)+"</td>";

    qDebug()<<ui->peoplemeet->item(i,0);
    //姓名
    if(ui->peoplemeet->item(i,0)!=NULL)
        html += "<td>"+ui->peoplemeet->item(i,0)->text()+"</td>";
    else
        html += "<td></td>";
    //现任
    if(ui->peoplemeet->item(i,5)!=NULL)
        html += "<td>"+ui->peoplemeet->item(i,5)->text()+"</td>";
    else
        html += "<td></td>";
    //现任职务任职时间
    //证件号查找
    QString id=ui->peoplemeet->item(i,2)->text();//证件号
    QSqlQuery qq("select PostTime from Post where IDNum='"+id+"' and QualifyType='0'");
    if(qq.next()){
            html += "<td>"+qq.value(0).toString()+"</td>";
    }
    else
        html += "<td></td>";
    //拟任
    if(ui->peoplemeet->item(i,6)!=NULL)
        html += "<td>"+ui->peoplemeet->item(i,6)->text()+"</td>";
    else
        html += "<td></td>";
    //拟免
    if(ui->peoplemeet->item(i,7)!=NULL)
        html += "<td>"+ui->peoplemeet->item(i,7)->text()+"</td>";
    else
        html += "<td></td>";

    QSqlQuery qqq("select NativePlace,Sex,Birth,JoinWorkTime,PartyTime from CadreInfo where IDNum='"+id+"'");
    if(qqq.next()){
        //籍贯,取出的是id
        QSqlQuery native("select AdminArea from AdminAreaCode where AdminAreaID='"+qqq.value(0).toString()+"'");
        while(native.next())
        html += "<td>"+native.value(0).toString()+"</td>";

        //性别
        if(qqq.value(1).toString()=="0")
        html += "<td>男</td>";
        else
        html += "<td>女</td>";
        //出生年月
        html += "<td>"+qqq.value(2).toString()+"</td>";
        //工作时间
        html += "<td>"+qqq.value(3).toString()+"</td>";
        //入党时间
        html += "<td>"+qqq.value(4).toString()+"</td>";
    }
    else
    {
        html += "<td></td>";
        html += "<td></td>";
        html += "<td></td>";
        html += "<td></td>";
        html += "<td></td>";
    }
    //最高学历
    QSqlQuery qqqq("select EduName from Edu where IDNum='"+id+"'");
    QStringList edu;//学历id数组
    while(qqqq.next()){
        QString num=qqqq.value(0).toString().left(1);
        edu.append(num);
    }
    if(edu.contains("1"))
        html += "<td>研究生</td>";
    else if(edu.contains("2"))
        html += "<td>本科生</td>";
    else if(edu.contains("3"))
        html += "<td>大专</td>";
    else if(edu.contains("4"))
        html += "<td>中专/职高/技校</td>";
    else
        html += "<th>高中及以下</th>";
    //html += "<th>"+ui->tableWidget->item(ui->tableWidget->currentRow(),2)->text()+"</th>";
    html += "</tr>";
    count--;
    i++;
    //j++;
    }
    html += "</table>";
    html += "</body>";
    html += "<ml>";
return html;
}
//表决票槽函数
void meetingWay::out_jduge(){
    int row=ui->meetingTable->currentRow();
    if(row==-1){
        QMessageBox::information(this,"","未选会议方案！");
        return;
    }
            QString filePth = QCoreApplication::applicationDirPath() + "/";
            QString fileName = QFileDialog::getSaveFileName(this, tr("导出PDF文件"), filePth, "*.pdf");
            if (!fileName.isEmpty())
            {
                // 如果文件后缀为空，则默认使用.pdf
                if (QFileInfo(fileName).suffix().isEmpty())
                {
                    fileName.append(".pdf");
                }
                QPrinter *printer = new QPrinter(QPrinter::ScreenResolution);
                // 指定输出格式为pdf
                printer->setPageSize(QPrinter::A4);
                printer->setOutputFormat(QPrinter::PdfFormat);
                printer->setOutputFileName(fileName);

                //{
    //            QPainter text_painter(this);
    //            text_painter.begin(printer);
    //            QList<QTableWidgetItem*>items=ui->tableWidget->selectedItems();
    //            //QString str = ui->tableWidget->item(i,0)->text();
    //           QString date=QString("报送日期："+items.at(0)->text());
    //            QString unit=QString("报送单位："+items.at(1)->text());
    //           QString envelope=QString("原信封号："+items.at(2)->text());
    //            QString copies=QString("报送份数："+items.at(3)->text());
    //            QString content=QString("报送内容："+items.at(4)->text());
    //            //for(int i=0;i<5;i++)
    //            text_painter.drawText(350,0,"报送信息");
    //                text_painter.drawText(10,1*30,date);
    //                text_painter.drawText(10,2*30,unit);
    //                text_painter.drawText(10,3*30,envelope);
    //                text_painter.drawText(10,4*30,copies);
    //                text_painter.drawText(10,5*30,content);
    //            //按照坐标（或矩形）输出,文本为QString类型，有多种重载函数，随便用哪一种
    //            text_painter.end();
   // }
                QTextDocument text_document;
                text_document.setHtml(jduge_html(fileName));
                text_document.print(printer);
                text_document.end();
        }

}

//统计槽函数
void meetingWay::out_statistic(){
    int row=ui->meetingTable->currentRow();
    if(row==-1){
        QMessageBox::information(this,"","未选会议方案！");
        return;
    }
            QString filePth = QCoreApplication::applicationDirPath() + "/";
            QString fileName = QFileDialog::getSaveFileName(this, tr("导出PDF文件"), filePth, "*.pdf");
            if (!fileName.isEmpty())
            {
                // 如果文件后缀为空，则默认使用.pdf
                if (QFileInfo(fileName).suffix().isEmpty())
                {
                    fileName.append(".pdf");
                }
                QPrinter *printer = new QPrinter(QPrinter::ScreenResolution);
                // 指定输出格式为pdf
                printer->setPageSize(QPrinter::A4);
                printer->setOutputFormat(QPrinter::PdfFormat);
                printer->setOutputFileName(fileName);

                //{
    //            QPainter text_painter(this);
    //            text_painter.begin(printer);
    //            QList<QTableWidgetItem*>items=ui->tableWidget->selectedItems();
    //            //QString str = ui->tableWidget->item(i,0)->text();
    //           QString date=QString("报送日期："+items.at(0)->text());
    //            QString unit=QString("报送单位："+items.at(1)->text());
    //           QString envelope=QString("原信封号："+items.at(2)->text());
    //            QString copies=QString("报送份数："+items.at(3)->text());
    //            QString content=QString("报送内容："+items.at(4)->text());
    //            //for(int i=0;i<5;i++)
    //            text_painter.drawText(350,0,"报送信息");
    //                text_painter.drawText(10,1*30,date);
    //                text_painter.drawText(10,2*30,unit);
    //                text_painter.drawText(10,3*30,envelope);
    //                text_painter.drawText(10,4*30,copies);
    //                text_painter.drawText(10,5*30,content);
    //            //按照坐标（或矩形）输出,文本为QString类型，有多种重载函数，随便用哪一种
    //            text_painter.end();
   // }
                QTextDocument text_document;
                text_document.setHtml(statistic_html(fileName));
                text_document.print(printer);
                text_document.end();
        }

}

//干部槽函数
void meetingWay::out_cadre(){
    int row=ui->meetingTable->currentRow();
    if(row==-1){
        QMessageBox::information(this,"","未选会议方案！");
        return;
    }
            QString filePth = QCoreApplication::applicationDirPath() + "/";
            QString fileName = QFileDialog::getSaveFileName(this, tr("导出PDF文件"), filePth, "*.pdf");
            if (!fileName.isEmpty())
            {
                // 如果文件后缀为空，则默认使用.pdf
                if (QFileInfo(fileName).suffix().isEmpty())
                {
                    fileName.append(".pdf");
                }
                QPrinter *printer = new QPrinter(QPrinter::ScreenResolution);
                // 指定输出格式为pdf
                printer->setPageSize(QPrinter::A4);
                printer->setOutputFormat(QPrinter::PdfFormat);
                printer->setOutputFileName(fileName);

                //{
    //            QPainter text_painter(this);
    //            text_painter.begin(printer);
    //            QList<QTableWidgetItem*>items=ui->tableWidget->selectedItems();
    //            //QString str = ui->tableWidget->item(i,0)->text();
    //           QString date=QString("报送日期："+items.at(0)->text());
    //            QString unit=QString("报送单位："+items.at(1)->text());
    //           QString envelope=QString("原信封号："+items.at(2)->text());
    //            QString copies=QString("报送份数："+items.at(3)->text());
    //            QString content=QString("报送内容："+items.at(4)->text());
    //            //for(int i=0;i<5;i++)
    //            text_painter.drawText(350,0,"报送信息");
    //                text_painter.drawText(10,1*30,date);
    //                text_painter.drawText(10,2*30,unit);
    //                text_painter.drawText(10,3*30,envelope);
    //                text_painter.drawText(10,4*30,copies);
    //                text_painter.drawText(10,5*30,content);
    //            //按照坐标（或矩形）输出,文本为QString类型，有多种重载函数，随便用哪一种
    //            text_painter.end();
   // }
                QTextDocument text_document;
                text_document.setHtml(cadre_html(fileName));
                text_document.print(printer);
                text_document.end();
        }

}

/*弃用了
void meetingWay::add_meet(){
   meet_dialog=new meetDialog(this);
   meet_dialog->setModal(true);
   meet_dialog->show();
}*/

//用这个添加方案
void meetingWay::click_lock(){
        QString meetName=ui->meetingName->text();
        QString start=ui->sdateTime->text();
        QString end=ui->edateTime->text();
        QString type=ui->meetTypeBox->currentText();
        QString note=ui->note->text();
        if(meetName==""){
            QMessageBox::information(this,"提示信息","会议名称不能为空！");
            return;
        }
        QSqlQuery qu("select MeetingID from Meeting where StartTime='"+start+"' and MeetingName='"+meetName+"'");
        if(qu.next())
        {
            QMessageBox::information(this,"提示信息","会议已存在，不可重复添加！");
            return;
        }
        QSqlQuery query;
        QString sql="INSERT INTO Meeting(StartTime,EndTime,MeetingName,MeetingType,Note)VALUES('"+start+"','"+end+"','"+meetName+"','"+type+"','"+note+"')";
        bool ok=query.exec(sql);
        //qDebug()<<ok<<start;
        showdatabase();
}
void meetingWay::del_meet(){
    int row=ui->meetingTable->currentRow();
    if(row==-1){
        QMessageBox::information(this,"提示信息","未选中删除行！");
        return;
    }
    //获取meetingid
    QString meetdate=ui->meetingTable->item(row,0)->text();
    QString meetname=ui->meetingTable->item(row,1)->text();

    //sqlconnect(db);
    QSqlQuery query;
    QString sql="DELETE FROM Meeting WHERE StartTime='"+meetdate+"' and MeetingName='"+meetname+"'";

    bool ok=query.exec(sql);
    if(ok)
    {
        qDebug()<<"删除成功！！";
        ui->meetingTable->removeRow(row);
        ui->peoplemeet->setRowCount(0);
        clearTable();
        showdatabase();
    }
    else
    {
            qDebug()<<"eeeeee方案删除失败";
    }
    //this->db.close();

    //ui->meetingTable->removeRow(item->row());
}
//获取信号槽函数
void meetingWay::add_record(){
    per_dialog=new meetPersonDialog(this);
    connect(this,SIGNAL(sendMeetID(QString)),per_dialog,SLOT(reciveMeetID(QString)));
    int row=ui->meetingTable->currentRow();
    if(row==-1){
        QMessageBox::information(this,"提示信息","未选会议方案！");
        return;
    }
    //获取meetingid
    QString strid;
    QSqlQuery meetid("select MeetingID from Meeting where StartTime='"+ui->meetingTable->item(row,0)->text()+"' and MeetingName='"+ui->meetingTable->item(row,1)->text()+"'");
    while(meetid.next()){
        strid=meetid.value(0).toString();
    }
    emit sendMeetID(strid);
    per_dialog->setModal(true);
    per_dialog->show();
}
void meetingWay::del_record(){
    int row=ui->peoplemeet->currentRow();//获得会议人员当前行

    if(row==-1){
        QMessageBox::information(this,"提示信息","未选中删除行！");
        return;
    }
    //获取meetingid，用于删除sql判断条件
    int wayrow=ui->meetingTable->currentRow();
    if(wayrow==-1){
        QMessageBox::information(this,"提示信息","未选中会议方案！");
        return;
    }
    QString strid;
    QSqlQuery meetid("select MeetingID from Meeting where (StartTime='"+ui->meetingTable->item(wayrow,0)->text()+"' and MeetingName='"+ui->meetingTable->item(wayrow,1)->text()+"')");
    while(meetid.next()){
        strid=meetid.value(0).toString();
    }
    //获取身份证
    QTableWidgetItem *numid =new QTableWidgetItem;
    numid=ui->peoplemeet->item(row,2);
    QString id=numid->text();

        qDebug()<<"dhaekhuhefuia  "<<row<<"    "<<strid<<"  "<<id;
    //sqlconnect(db);
    QSqlQuery query;
    QString sql="DELETE FROM MeetingPeople WHERE MeetingID='"+strid+"' and IDNum='"+id+"'";
    bool ok=query.exec(sql);
    if(ok)
    {
        qDebug()<<"删除成功！！";
        ui->peoplemeet->removeRow(row);
        clearTable();
        showMeetPer();
    }
    else
    {
            qDebug()<<"eeeeee";
    }

    //this->db.close();
}

void meetingWay::up_meet(){
    int m_CurrentRow = ui->meetingTable->currentRow();//获取当前行的Index
    int columnC=ui->meetingTable-> columnCount();
      if (m_CurrentRow != -1)//如果选中了数据，（未选择数据之前，返回值是-1）
      {
          if (m_CurrentRow != 0)//如果选定行不在第一行
          {
              SwapTwoRow(ui->meetingTable,m_CurrentRow, m_CurrentRow - 1,columnC);
              ui->meetingTable->setCurrentCell(m_CurrentRow - 1, QItemSelectionModel::Select);//移动过后继续选定该行
          }
      }
      else {
          if (ui->meetingTable->rowCount() != 0)//如果有数据，但是currentRow=--1 说明没有选择数据,把焦点定位到第一行
          {
              QMessageBox::critical(this, tr("出现错误"), tr("无法移动：未选中数据"));
          }
          else
          {
              QMessageBox::critical(this, tr("出现错误"), tr("无法移动：表格没有数据"));
          }
      }

}
void meetingWay::down_meet(){
    int m_CurrentRow = ui->meetingTable->currentRow();
    int columnC=ui->meetingTable-> columnCount();
        if (m_CurrentRow != -1)//如果选中了一行
        {
            if (m_CurrentRow != (ui->meetingTable->rowCount() - 1))//如果不是最后一行
            {
                SwapTwoRow(ui->meetingTable,m_CurrentRow, m_CurrentRow + 1,columnC);
                ui->meetingTable->setCurrentCell(m_CurrentRow + 1, QItemSelectionModel::Select);//移动过后继续选定该行
            }

        }
        else {
            if (ui->meetingTable->rowCount() != 0)//如果有数据，但是currentRow=--1 说明没有选择数据,把焦点定位到第一行
            {
                QMessageBox::critical(this, tr("出现错误"), tr("无法移动：未选中数据"));
            }
            else
            {
                QMessageBox::critical(this, tr("出现错误"), tr("无法移动：表格没有数据"));
            }
        }
}

void meetingWay::SwapTwoRow(QTableWidget* ContentTW,int selectRow, int targetRow,int columnCount) {
    QStringList selectRowLine, targetRowLine;//创建两个QStringList用于储存表格数据
    //int rowCount=3;//五列
  //  ui->ContentTW->showColumn(3);
   // QMessageBox::critical(this, tr("出现错误"), tr("无法移动：表格没有数据"));
    for (int i = 0; i < columnCount; i++)
    {
        selectRowLine.append(ContentTW->item(selectRow, i)->text());//获取文本，并添加进QStringLine
        targetRowLine.append(ContentTW->item(targetRow, i)->text());
    }
    for (int i = 0; i < columnCount; i++)
    {
        ContentTW->setItem(selectRow, i, new QTableWidgetItem(targetRowLine.at(i)));//设置文本
        ContentTW->setItem(targetRow, i, new QTableWidgetItem(selectRowLine.at(i)));
    }
}

void meetingWay::up_per(){
    int m_CurrentRow = ui->peoplemeet->currentRow();//获取当前行的Index
    int columnC=ui->peoplemeet-> columnCount();
      if (m_CurrentRow != -1)//如果选中了数据，（未选择数据之前，返回值是-1）
      {
          if (m_CurrentRow != 0)//如果选定行不在第一行
          {
              //SwapTwoRow(ui->peoplemeet,m_CurrentRow, m_CurrentRow - 1,columnC);
              ui->peoplemeet->setCurrentCell(m_CurrentRow - 1, QItemSelectionModel::Select);//移动过后继续选定该行
          }
      }
      else {
          if (ui->peoplemeet->rowCount() != 0)//如果有数据，但是currentRow=--1 说明没有选择数据,把焦点定位到第一行
          {
              QMessageBox::critical(this, tr("出现错误"), tr("无法移动：未选中数据"));
          }
          else
          {
              QMessageBox::critical(this, tr("出现错误"), tr("无法移动：表格没有数据"));
          }
      }
}


void meetingWay::down_per(){
    int m_CurrentRow = ui->peoplemeet->currentRow();
    int columnC=ui->peoplemeet-> columnCount();
        if (m_CurrentRow != -1)//如果选中了一行
        {
            if (m_CurrentRow != (ui->peoplemeet->rowCount() - 1))//如果不是最后一行
            {
                //SwapTwoRow(ui->peoplemeet,m_CurrentRow, m_CurrentRow - 1,columnC);
                ui->peoplemeet->setCurrentCell(m_CurrentRow + 1, QItemSelectionModel::Select);//移动过后继续选定该行
            }

        }
        else {
            if (ui->peoplemeet->rowCount() != 0)//如果有数据，但是currentRow=--1 说明没有选择数据,把焦点定位到第一行
            {
                QMessageBox::critical(this, tr("出现错误"), tr("无法移动：未选中数据"));
            }
            else
            {
                QMessageBox::critical(this, tr("出现错误"), tr("无法移动：表格没有数据"));
            }
        }
}
/*/编辑职务
void meetingWay::editPost(){
    //ui->familyTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
    int wayrow=ui->meetingTable->currentRow();
    if(wayrow==-1){
        QMessageBox::information(this,"","未选中会议方案！");
        return;
    }
    int rows=ui->peoplemeet->rowCount();//人员数
    qDebug()<<"nimeide";
    for(int i=0;i<rows;i++){
        ui->peoplemeet->item(i,5)->setFlags(ui->peoplemeet->item(i, 5)->flags() | Qt::ItemIsEnabled);
        ui->peoplemeet->item(i,5)->setBackgroundColor(QColor(40,143,218));
        ui->peoplemeet->item(i,6)->setFlags(Qt::ItemIsEnabled);
        ui->peoplemeet->item(i,7)->setFlags(Qt::ItemIsEnabled);
    }
}*/

void meetingWay::clearTable(){
    //ui->peoplemeet->setRowCount(0);
    ui->eduTable->setRowCount(0);
    ui->workExperience->setRowCount(0);//连行也清除掉
    ui->checkTable->setRowCount(0);
    ui->rewardTable->setRowCount(0);
    ui->punishTable->setRowCount(0);
    ui->familyTable->setRowCount(0);
    ui->name->setText("");
    ui->usedname->setText("");
    ui->IDType->setText("");
    ui->IDNum->setText("");

    ui->bornPlace->setText("");
    ui->workdate->setText("");
    ui->sex->setText("");
    ui->health->setText("");

    ui->nation->setText("");
    ui->nativePlace->setText("");
    ui->bornPlace->setText("");
    ui->growPlace->setText("");

    ui->politic->setText("");
    ui->partyDate->setText("");
    ui->demoParty->setText("");
    ui->retirechange->setText("");

    ui->speciality->setText("");
    ui->manageID->setText("");
    ui->idencate->setText("");
    ui->threeone->setText("");
    ui->baseexper->setText("");
    ui->unitid->setText("");
    ui->phone->setText("");

    ui->rankid->setText("");
    ui->daiyuEdit->setText("");
    ui->ranktime->setText("");


}

/*
 *
 *
 *
 *
 *
 * 对数据库的操作
 *
 *
 *
 *
*/
//退出对话框刷新,弹出对话框刷新，显示会议方案
void meetingWay::showdatabase()
{
    ui->meetingTable->setRowCount(0);
    QSqlQuery query;
    query.exec("select *from Meeting");

    while(query.next())
    {
        int rowc=ui->meetingTable->rowCount();//获取行数
        ui->meetingTable->insertRow(rowc);
        QString a=query.value(1).toString();
        ui->meetingTable->setItem(rowc,0,new QTableWidgetItem(a));
        QString z=query.value(3).toString();
        ui->meetingTable->setItem(rowc,1,new QTableWidgetItem(z));
        QString m=query.value(4).toString();
        ui->meetingTable->setItem(rowc,2,new QTableWidgetItem(m));
        QString n=query.value(5).toString();
        ui->meetingTable->setItem(rowc,3,new QTableWidgetItem(n));
        //QString b=query.value(5).toString();
        //ui->meetingTable->setItem(rowc,4,new QTableWidgetItem(b));

    }
     //this->db.close();

}
void meetingWay::showMeetPer(){
    //sqlconnect(db);
    ui->peoplemeet->setRowCount(0);
    int row=ui->meetingTable->currentRow();
    if(row==-1){
        return;
    }
    //获取meetingid
    QString strid;
    QSqlQuery meetid("select MeetingID from Meeting where StartTime='"+ui->meetingTable->item(row,0)->text()+"' and MeetingName='"+ui->meetingTable->item(row,1)->text()+"'");
    while(meetid.next()){
        strid=meetid.value(0).toString();
    }
    QSqlQuery query;
    query.exec("select IDNum from MeetingPeople where MeetingID='"+strid+"'");
    while(query.next()){

        int rowc=ui->peoplemeet->rowCount();//获取行数
        ui->peoplemeet->insertRow(rowc);
        ui->peoplemeet->setItem(rowc,4,new QTableWidgetItem(""));
        ui->peoplemeet->setItem(rowc,5,new QTableWidgetItem(""));
        ui->peoplemeet->setItem(rowc,6,new QTableWidgetItem(""));
        ui->peoplemeet->setItem(rowc,7,new QTableWidgetItem(""));
        //身份证号
        QString a=query.value(0).toString();
        ui->peoplemeet->setItem(rowc,2,new QTableWidgetItem(a));
        //CadreInfo.IDNum='09090909090' and Post.IDNum='09090909090'
        QString sql2="select CadreName,Birth,Sex from CadreInfo where CadreInfo.IDNum='"+a+"'";
        QSqlQuery query2;
        bool ok2=query2.exec(sql2);
        //qDebug()<<"chazhao"<<ok2;
        while(query2.next()){
            //姓名
            QString m=query2.value(0).toString();
            ui->peoplemeet->setItem(rowc,0,new QTableWidgetItem(m));
            //出生日期
            QString m1=query2.value(1).toString();
            ui->peoplemeet->setItem(rowc,1,new QTableWidgetItem(m1));
            //性别
            QString m2=query2.value(2).toString();
            if(m2==QString::fromLocal8Bit("1"))
            ui->peoplemeet->setItem(rowc,3,new QTableWidgetItem("男"));
            if(m2==QString::fromLocal8Bit("0"))
            ui->peoplemeet->setItem(rowc,3,new QTableWidgetItem("女"));

            qDebug()<<m<<m1<<m2;
        }
        //职务
        query2.exec("select PostNumber,PostName,QualifyType from Post where IDNum='"+a+"'");
        while(query2.next()){
            //任免文号
            QString m3=query2.value(0).toString();
            ui->peoplemeet->setItem(rowc,4,new QTableWidgetItem(m3));
            //职务名称
            QString m4=query2.value(1).toString();
            //职务类型
            QString m5=query2.value(2).toString();
            if(m5==QString::fromLocal8Bit("0"))
                ui->peoplemeet->setItem(rowc,5,new QTableWidgetItem(m4));
            if(m5==QString::fromLocal8Bit("1"))
                ui->peoplemeet->setItem(rowc,6,new QTableWidgetItem(m4));
            if(m5==QString::fromLocal8Bit("2"))
                ui->peoplemeet->setItem(rowc,7,new QTableWidgetItem(m4));
        }
    }
/*    int rowc=ui->peoplemeet->rowCount();//获取行数
    for(int iRow = 0; iRow < rowc; ++ iRow)
    {
        for(int icolumn = 0; icolumn < 5; ++ icolumn)

                ui->peoplemeet->item(iRow, icolumn)->setFlags(ui->peoplemeet->item(iRow, icolumn)->flags() &(~Qt::ItemIsEnabled));

            //ui->peoplemeet->item(iRow,5)->setBackgroundColor(QColor(40,143,218));


    }*/
    //db.close();
}

void meetingWay::showMeetPerInfo(){
    //sqlconnect(db);
    clearTable();
    int row=ui->meetingTable->currentRow();
    if(row==-1){
        return;
    }
    int row2=ui->peoplemeet->currentRow();
    if(row2==-1){
        QMessageBox::information(this,"","未选中行！");
        return;
    }
    QTableWidgetItem *numid = new QTableWidgetItem;
    numid = ui->peoplemeet->item(row2,2);
    QString nid=numid->text();
 /*   //职务
    QSqlQuery query1;
    QString sql1="select PostName,QualifyType from Post where Post.IDNum='"+nid+"'";
    bool ok=query1.exec(sql1);
    while(query1.next()){
        //职务名称
        QString s1=query1.value(0).toString();
        //任免类型
        QString s2=query1.value(1).toString();
        //现任
        if(s2==QString::fromLocal8Bit("0"))
        ui->postNow->setText(s1);
        //拟任
        if(s2==QString::fromLocal8Bit("1"))
        ui->postWill->setText(s1);
        //拟免
        if(s2==QString::fromLocal8Bit("2"))
        ui->postQuit->setText(s1);
    }*/
    //学历
    QSqlQuery query2;
    QString sql2="select * from Edu where Edu.IDNum='"+nid+"'";
    bool ok2=query2.exec(sql2);
    while(query2.next()){
        int rowc=ui->eduTable->rowCount();//获取行数
        ui->eduTable->insertRow(rowc);
        //入学时间
        QString s1=query2.value(1).toString();
        ui->eduTable->setItem(rowc,0,new QTableWidgetItem(s1));
        //结业时间
        QString s2=query2.value(2).toString();
        ui->eduTable->setItem(rowc,1,new QTableWidgetItem(s2));
        //学历完成状况
        QString a4=query2.value(3).toString();
        if(a4=="1")
            a4="毕业";
        if(a4=="2")
            a4="结业";
        if(a4=="3")
            a4="未结业";
        if(a4=="4")
            a4="肄业";
        if(a4=="9")
            a4="其他";
        ui->eduTable->setItem(rowc,2,new QTableWidgetItem(a4));
        //学历
        QString s4=query2.value(4).toString();
        QSqlQuery q11("select Education from EducationCode where EducationID='"+s4+"'" );
        while (q11.next()) {
            s4=q11.value(0).toString();
        }
        ui->eduTable->setItem(rowc,3,new QTableWidgetItem(s4));

        //学位
        QString s5=query2.value(5).toString();
        QSqlQuery q22("select Degree from DegreeCode where DegreeID='"+s5+"'" );
        while (q22.next()) {
            s5=q22.value(0).toString();
        }
        ui->eduTable->setItem(rowc,4,new QTableWidgetItem(s5));

        //学校
        QString s6=query2.value(6).toString();
        ui->eduTable->setItem(rowc,5,new QTableWidgetItem(s6));
        //专业
        QString s7=query2.value(7).toString();
        ui->eduTable->setItem(rowc,6,new QTableWidgetItem(s7));
        //在职或全日
        QString s8=query2.value(8).toString();
        if(s8=="0")
            s8="在职";
        if(s8=="1")
            s8="全日制";
        ui->eduTable->setItem(rowc,7,new QTableWidgetItem(s8));
    }
    //工作经历
    QSqlQuery query3;
    QString sql3="select * from Experience where Experience.IDNum='"+nid+"'";
    bool ok3=query3.exec(sql3);
    while(query3.next()){
        int rowc=ui->workExperience->rowCount();//获取行数
        ui->workExperience->insertRow(rowc);
        //开始时间
        QString s1=query3.value(1).toString();
        ui->workExperience->setItem(rowc,0,new QTableWidgetItem(s1));
        //结束时间
        QString s2=query3.value(2).toString();
        ui->workExperience->setItem(rowc,1,new QTableWidgetItem(s2));
        //单位
        QString s3=query3.value(3).toString();
        ui->workExperience->setItem(rowc,2,new QTableWidgetItem(s3));
        //工作
        QString s4=query3.value(4).toString();
        ui->workExperience->setItem(rowc,3,new QTableWidgetItem(s4));
        }
    //考核
    QSqlQuery query4;
    //Check是mysql中的关键字
    QString sql4="select * from `Check` where `Check`.IDNum='"+nid+"'";
    bool ok4=query4.exec(sql4);
    qDebug()<<ok4<<"考核";
    while(query4.next()){
        int rowc=ui->checkTable->rowCount();//获取行数
        ui->checkTable->insertRow(rowc);
        //年度
        QString s1=query4.value(1).toString();
        ui->checkTable->setItem(rowc,0,new QTableWidgetItem(s1));
        //结果
        QString s2=query4.value(2).toString();
        ui->checkTable->setItem(rowc,1,new QTableWidgetItem(s2));
        qDebug()<<s1<<s2;
        }

    //奖励
    QSqlQuery query5;
    QString sql5="select * from `Reward` where `Reward`.IDNum='"+nid+"'";
    bool ok5=query5.exec(sql5);
    qDebug()<<ok5<<"奖励";
    while(query5.next()){
        int rowc=ui->rewardTable->rowCount();//获取行数
        ui->rewardTable->insertRow(rowc);
        //时间
        QString s1=query5.value(1).toString();
        ui->rewardTable->setItem(rowc,0,new QTableWidgetItem(s1));
        //类型
        QString s2=query5.value(2).toString();
        ui->rewardTable->setItem(rowc,1,new QTableWidgetItem(s2));
        //名称
        QString s3=query5.value(3).toString();
        ui->rewardTable->setItem(rowc,2,new QTableWidgetItem(s3));
        //等级
        QString s4=query5.value(4).toString();
        ui->rewardTable->setItem(rowc,3,new QTableWidgetItem(s4));
        //排名
        QString s5=query5.value(5).toString();
        ui->rewardTable->setItem(rowc,4,new QTableWidgetItem(s5));
        }

    //惩处
    QSqlQuery query6;
    QString sql6="select * from `Punish` where `Punish`.IDNum='"+nid+"'";
    bool ok6=query6.exec(sql6);
    qDebug()<<ok6<<"惩处";
    while(query6.next()){
        int rowc=ui->punishTable->rowCount();//获取行数
        ui->punishTable->insertRow(rowc);
        //时间
        QString s1=query6.value(1).toString();
        ui->punishTable->setItem(rowc,0,new QTableWidgetItem(s1));
        //类型
        QString s2=query6.value(2).toString();
        ui->punishTable->setItem(rowc,1,new QTableWidgetItem(s2));
        //宣布机关
        QString s3=query6.value(3).toString();
        ui->punishTable->setItem(rowc,2,new QTableWidgetItem(s3));
        //名称
        QString s4=query6.value(4).toString();
        ui->punishTable->setItem(rowc,3,new QTableWidgetItem(s4));
        //原因
        QString s5=query6.value(5).toString();
        ui->punishTable->setItem(rowc,4,new QTableWidgetItem(s5));
        }

    //家庭关系
    QSqlQuery query7;
    QString sql7="select * from `Family` where `Family`.IDNum='"+nid+"'";
    bool ok7=query7.exec(sql7);
    qDebug()<<ok7<<"家庭关系";
    while(query7.next()){
        int rowc=ui->familyTable->rowCount();//获取行数
        ui->familyTable->insertRow(rowc);
        //姓名
        QString s1=query7.value(1).toString();
        ui->familyTable->setItem(rowc,0,new QTableWidgetItem(s1));
        //出生日期
        QString s2=query7.value(2).toString();
        ui->familyTable->setItem(rowc,1,new QTableWidgetItem(s2));
        //关系
        QString s3=query7.value(3).toString();
        ui->familyTable->setItem(rowc,2,new QTableWidgetItem(s3));
        //政治面貌id
        QString s4=query7.value(4).toString();
        QSqlQuery query8("SELECT Politic FROM PoliticCode where PoliticID='"+s4+"'");
        while (query8.next()) {
            s4= query8.value(0).toString();
        }
        ui->familyTable->setItem(rowc,3,new QTableWidgetItem(s4));
        //单位
        QString s5=query7.value(5).toString();
        ui->familyTable->setItem(rowc,4,new QTableWidgetItem(s5));
        //职业
        QString s6=query7.value(6).toString();
        ui->familyTable->setItem(rowc,5,new QTableWidgetItem(s6));
        //证件号
        QString s7=query7.value(8).toString();
        ui->familyTable->setItem(rowc,6,new QTableWidgetItem(s7));
        //备注
        QString s8=query7.value(9).toString();
        ui->familyTable->setItem(rowc,7,new QTableWidgetItem(s8));
        //状态id
        QString s9=query7.value(10).toString();
        QSqlQuery sss("select FamilyStatus from FamilyStatusCode where FamilyStatusID='"+s9+"'");
        while (sss.next()) {
            s9=sss.value(0).toString();
        }
        qDebug()<<s9;
        ui->familyTable->setItem(rowc,8,new QTableWidgetItem(s9));
        }
    //基本信息
    QSqlQuery query9;
    QString sql9="select * from `CadreInfo` where IDNum='"+nid+"'";
    bool ok9=query9.exec(sql9);
    qDebug()<<ok9<<"基本信息";
    while(query9.next()){
        //姓名
        QString s1=query9.value(0).toString();
        ui->name->setText(s1);
        //曾用名
        QString s2=query9.value(1).toString();
        ui->usedname->setText(s2);
        //证件类型id
        QString s3=query9.value(2).toString();
        QSqlQuery queryother("SELECT CredType FROM CredTypeCode where CredTypeID='"+s3+"'");
        while (queryother.next()) {
            s3= queryother.value(0).toString();
        }
        ui->IDType->setText(s3);
        //证件号
        QString s4=query9.value(3).toString();
        ui->IDNum->setText(s4);
        //出生日期
        QString borndate=query9.value(4).toString();
        ui->borndate->setText(borndate);
        //工作时间
        QString joinwork=query9.value(5).toString();
        ui->workdate->setText(joinwork);
        //性别
        QString sex=query9.value(6).toString();
        if(sex==QString::fromLocal8Bit("0"))
            sex="男";
        if(sex==QString::fromLocal8Bit("1"))
            sex="女";
        ui->sex->setText(sex);
        //Health
        QString health=query9.value(7).toString();
        ui->health->setText(health);
        //民族
        QString a4=query9.value(8).toString();
        QSqlQuery qu;
        qu.exec("select Nation from NationCode where NationID='"+a4+"'");
        while(qu.next()){
            a4=qu.value(0).toString();
        }
        ui->nation->setText(a4);
        //籍贯
        QString place1=query9.value(9).toString();
        ui->nativePlace->setText(place1);
        //出生地
        QString place2=query9.value(10).toString();
        ui->bornPlace->setText(place2);
        //成长地
        QString place3=query9.value(11).toString();
        ui->growPlace->setText(place3);
        //政治面貌
        QString poli=query9.value(12).toString();
        qu.exec("select Politic from PoliticCode where PoliticID='"+poli+"'");
        while(qu.next()){
            poli=qu.value(0).toString();
        }
        ui->politic->setText(poli);
        //政党时间
        QString partyda=query9.value(13).toString();
        ui->partyDate->setText(partyda);
        //民主党派
        QString democracy=query9.value(14).toString();
        if(democracy=="0")
            ui->demoParty->setText("是");
        if(democracy=="1")
            ui->demoParty->setText("否");
        //退休改非
        QString retire=query9.value(15).toString();
        if(retire=="0")
            ui->retirechange->setText("是");
        if(retire=="1")
            ui->retirechange->setText("否");
        //专长
        QString special=query9.value(16).toString();
        ui->speciality->setText(special);
        //干部状态
        QString status=query9.value(17).toString();
        QSqlQuery q("select ManageStatus from ManageStatusCode where ManageStatusID='"+status+"'");
        while (q.next()) {
            ui->manageID->setText(q.value(0).toString());
        }
        //身分类别
        QString idencate=query9.value(18).toString();
        ui->idencate->setText(idencate);
        //三龄一例
        QString threeone=query9.value(19).toString();
        if(threeone=="0")
            ui->threeone->setText("归档");
        if(threeone=="1")
            ui->threeone->setText("未归档");
        //电话
        QString phone=query9.value(20).toString();
        ui->phone->setText(phone);
        //基层
        QString jiceng=query9.value(21).toString();
        if(jiceng=="0")
            ui->baseexper->setText("有");
        if(jiceng=="1")
            ui->baseexper->setText("无");
        //单位
        QString unitid=query9.value(22).toString();
        QSqlQuery q2("select unitname from unit where unitid='"+unitid+"'");
        while (q2.next()) {
            ui->unitid->setText(q2.value(0).toString());
        }
        //职级
        QString rankid=query9.value(23).toString();
        QSqlQuery q3("select RankName from RankCode where RankID='"+rankid+"'");
        while (q3.next()) {
            ui->rankid->setText(q3.value(0).toString());
        }
        //级别时间
        QString rankdate=query9.value(24).toString();
        ui->ranktime->setText(rankdate);
        //级别待遇
        QString daiyu=query9.value(25).toString();
        ui->daiyuEdit->setText(daiyu);
    }
}
